<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>删除事件</title>
    <style>
    </style>
</head>

<body>
    <div id="root">
        <button>按钮1</button>
        <button>按钮2</button>
        <button>按钮3</button>
        <button>按钮4</button>
        <button>按钮5</button>
    </div>
</body>
<script>
    /* 
    删除事件(解绑事件)
            传统方式（传统绑定的事件才有用)
                 node.onclick=null
            新方式 removeEventListener (不能使用匿名函数)
                node.removeEventListener('click'，函数变量)
    */
   let bs= document.querySelectorAll('button')
   bs[1].onclick=function(){
    console.log('按钮')
   }
   let funs=[]
   for(let b of bs){
    funs.push(function () {
            console.log(this.innerHTML);
        })
        b.addEventListener('click',funs[funs.length-1])
   }
   bs[1].onclick=null
   bs[2].removeEventListener('click',funs[2])
</script>

</html>